package com.mall.sun.controller;

import com.mall.sun.exception.Errors;
import com.mall.sun.model.dto.ImageInputDTO;
import com.mall.sun.model.vo.ResultVO;
import com.mall.sun.service.ImageIdentifyService;
import com.mall.sun.utils.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * description:  <br>
 * date: 2021/12/9 21:58 <br>
 * author: ztz <br>
 * version: 1.0 <br>
 */
@RestController
@RequestMapping("/identify")
public class ImageIdentifyController {
    @Autowired
    ImageIdentifyService imageIdentifyService;

    @PostMapping("/plant")
    public ResultVO getImagePlant(@RequestBody ImageInputDTO inputDTO){
        try {
            List<com.mall.sun.model.dto.ImageIdentifyDTO> list = imageIdentifyService.getImageResult(inputDTO.getBase64());
            if(null == list || list.size() ==0){
               return CommonUtil.errorReturn(Errors.Image_CanNot_Identify);
            }else {
                return CommonUtil.ajaxReturn(list);
            }
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        return CommonUtil.errorReturn(Errors.Image_Error);
    }

}
